package com.etc;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@RestController
public class UserInfoController {

	@Autowired
	RestTemplate template;
	
	@GetMapping("login")
	public String login() {
		 String url = "http://localhost:10000/auth/login";
	        HttpHeaders headers = new HttpHeaders();
	        headers.setContentType(MediaType.APPLICATION_JSON);
	        headers.set("phone", "123456");
	        Map<String, Object> params = new HashMap<>();
	        params.put("username", "yyc");
	        params.put("email", "12306");
	        RestTemplate restTemplate = new RestTemplate();
//	        HttpEntity httpEntity = new HttpEntity(params,headers);
	       String body = "{\"username\":\"tom1\",\"password\":123456}";
	       HttpEntity httpEntity = new HttpEntity(body);
	        ResponseEntity<String> request = restTemplate.postForEntity(url, httpEntity,String.class);
	        System.out.println(request.getBody());
	        HttpHeaders header = request.getHeaders();
	        
	        System.out.println(header.get("token"));
		return "";
	}
}
